/***************************************************************
Copyright Statement:

This software/firmware and related documentation (EcoNet Software) 
are protected under relevant copyright laws. The information contained herein 
is confidential and proprietary to EcoNet (HK) Limited (EcoNet) and/or 
its licensors. Without the prior written permission of EcoNet and/or its licensors, 
any reproduction, modification, use or disclosure of EcoNet Software, and 
information contained herein, in whole or in part, shall be strictly prohibited.

EcoNet (HK) Limited  EcoNet. ALL RIGHTS RESERVED.

BY OPENING OR USING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY 
ACKNOWLEDGES AND AGREES THAT THE SOFTWARE/FIRMWARE AND ITS 
DOCUMENTATIONS (ECONET SOFTWARE) RECEIVED FROM ECONET 
AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON AN AS IS 
BASIS ONLY. ECONET EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, 
WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 
OR NON-INFRINGEMENT. NOR DOES ECONET PROVIDE ANY WARRANTY 
WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTIES WHICH 
MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE ECONET SOFTWARE. 
RECEIVER AGREES TO LOOK ONLY TO SUCH THIRD PARTIES FOR ANY AND ALL 
WARRANTY CLAIMS RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES 
THAT IT IS RECEIVERS SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD 
PARTY ALL PROPER LICENSES CONTAINED IN ECONET SOFTWARE.

ECONET SHALL NOT BE RESPONSIBLE FOR ANY ECONET SOFTWARE RELEASES 
MADE TO RECEIVERS SPECIFICATION OR CONFORMING TO A PARTICULAR 
STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND 
ECONET'S ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE ECONET 
SOFTWARE RELEASED HEREUNDER SHALL BE, AT ECONET'S SOLE OPTION, TO 
REVISE OR REPLACE THE ECONET SOFTWARE AT ISSUE OR REFUND ANY SOFTWARE 
LICENSE FEES OR SERVICE CHARGES PAID BY RECEIVER TO ECONET FOR SUCH 
ECONET SOFTWARE.
***************************************************************/

/************************************************************************
*                  I N C L U D E S
*************************************************************************
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <errno.h>
#include "omci_adpt_common.h"
#include "omci_adpt_general.h"
#include "omci_me_external.h"

#include "omci_adpt_private_voip.h"

/************************************************************************
*                  D E F I N E S   &   C O N S T A N T S
*************************************************************************
*/




/************************************************************************
*                  M A C R O S
*************************************************************************
*/    
#define MAX_LINE_NUM       256

/************************************************************************
*                  D A T A     T Y P E S
*************************************************************************
*/


/************************************************************************
*                  E X T E R N A L     D A T A   D E C L A R A T I O N S
*************************************************************************
*/



/************************************************************************
*                  F U N C T I O N   D E C L A R A T I O N S
*************************************************************************
*/

/************************************************************************
*                  P U B L I C   D A T A
*************************************************************************
*/

/************************************************************************
*                  P R I V A T E   D A T A
*************************************************************************
*/


/************************************************************************
*                  F U N C T I O N   D E F I N I T I O N S
*************************************************************************
*/

int omci_tcapi_set(char *node,char * attr, char *value)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_tcapi_nget(char* node, char* attr, char *retval, int retval_len)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_tcapi_commit(char *node)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_tcapi_save(void)
{	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}

int omci_adpt_set_emergency(uint8_t value)
{
#ifdef TCSUPPORT_OPENWRT
	char cmd[256] = {0};
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);

	if(0 == value){
		sprintf(cmd, "uci set gpon.ONU.EmergencyState=0");
		system(cmd);
	}else if(1 == value){
		sprintf(cmd, "uci set gpon.ONU.EmergencyState=1");
		system(cmd);
	}
	system("uci commit gpon");
#else
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
#endif
	return 0;
}

int omci_adpt_get_olt_type(void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}


/*OMCI Upgrade*/

int omci_image_get_version(char *version, uint8_t ver_len, uint8_t image_flag)
{
	//ALU OLT IOT Issue
	char softVersion[OMCI_VERSION_LENS] = "ECNT-SW-V1.0";
#ifdef TCSUPPORT_OPENWRT
	char buffer[16] = {0};

	if(image_flag == 0) {
		omci_lib_uci_get("gpon.SoftImage0.Version", buffer, sizeof(buffer));
	}
	else if(image_flag == 1) {
		omci_lib_uci_get("gpon.SoftImage1.Version", buffer, sizeof(buffer));
	}
	strncpy(softVersion, buffer, sizeof(softVersion));
	softVersion[sizeof(softVersion)-1] = '\0';
#endif
	
	if(NULL == version || ver_len < OMCI_VERSION_LENS){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "version == NULL or ver_len < 14!!!\n",__FUNCTION__,__LINE__);
		return -1;
	}
	
	memcpy(version,softVersion,OMCI_VERSION_LENS); 
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP. Set default version information for BSP\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_image_get_bootflag(uint8_t * pbootflag)
{
    blapi_pon_get_boot_flag(pbootflag);
    return 0;
}
int omci_image_set_bootflag(uint8_t bootflag)
{
    return blapi_pon_set_bootFlag_to_flash(bootflag);
}

int omci_image_save_state(softimage_state_t *softimage_state)
{
#ifdef TCSUPPORT_OPENWRT
	char tmp[15] = {0};
	char cmd[256] = {0};
	int i = 0;
	struct img_state{
		uint8_t commit;
		uint8_t active;
		uint8_t valid;
	};
	static struct  omciSoftwareImageState{
		struct img_state img0;
		struct img_state img1;
		char value[64];/*software image state type*/
	}mode_table[] = {
		/*	{image0_commit	image0_active	 image0_valid	},{   image1_commit    image1_active   image1_valid },		 "state"   */ 
		{{COMMITTED_IMAGE,	 ACTIVE_IMAGE,	 VALID_IMAGE,	},{UNCOMMITTED_IMAGE, INACTIVE_IMAGE, INVALID_IMAGE },"SOFTWARE_IMAGE_STATE_S1_0"},
		{{COMMITTED_IMAGE,	 ACTIVE_IMAGE,	 VALID_IMAGE,	},{UNCOMMITTED_IMAGE, INACTIVE_IMAGE, VALID_IMAGE	},"SOFTWARE_IMAGE_STATE_S3_0"},
		{{COMMITTED_IMAGE,	 INACTIVE_IMAGE, VALID_IMAGE,	},{UNCOMMITTED_IMAGE, ACTIVE_IMAGE,   VALID_IMAGE	},"SOFTWARE_IMAGE_STATE_S4_0"},
		{{UNCOMMITTED_IMAGE, ACTIVE_IMAGE,	 VALID_IMAGE,	},{COMMITTED_IMAGE,   INACTIVE_IMAGE, VALID_IMAGE	},"SOFTWARE_IMAGE_STATE_S4_1"},
		{{UNCOMMITTED_IMAGE, INACTIVE_IMAGE, VALID_IMAGE,	},{COMMITTED_IMAGE,   ACTIVE_IMAGE,   VALID_IMAGE	},"SOFTWARE_IMAGE_STATE_S3_1"},
		{{UNCOMMITTED_IMAGE, INACTIVE_IMAGE, INVALID_IMAGE, },{COMMITTED_IMAGE,   ACTIVE_IMAGE,   VALID_IMAGE	},"SOFTWARE_IMAGE_STATE_S1_1"},
	};
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d].\n",__FUNCTION__,__LINE__);
	if(NULL == softimage_state){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}
	memcpy(tmp,softimage_state->image0.version,14);
	sprintf(cmd, "uci set gpon.SoftImage0.Version=%s", tmp);
	system(cmd);
	sprintf(cmd, "uci set gpon.SoftImage0.Committed=%d", softimage_state->image0.committed);
	system(cmd);
	sprintf(cmd, "uci set gpon.SoftImage0.Active=%d", softimage_state->image0.active);
	system(cmd);
	sprintf(cmd, "uci set gpon.SoftImage0.Valid=%d", softimage_state->image0.valid);
	system(cmd);
	memcpy(tmp,softimage_state->image1.version,14);
	sprintf(cmd, "uci set gpon.SoftImage1.Version=%s", tmp);
	system(cmd);
	sprintf(cmd, "uci set gpon.SoftImage1.Committed=%d", softimage_state->image1.committed);
	system(cmd);
	sprintf(cmd, "uci set gpon.SoftImage1.Active=%d", softimage_state->image1.active);
	system(cmd);
	sprintf(cmd, "uci set gpon.SoftImage1.Valid=%d", softimage_state->image1.valid);
	system(cmd);
	
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE,"omci_image_save_state: image0_commit = %d image0_active = %d image0_valid = %d image1_commit = %d image1_active = %d image1_valid = %d \n",
		softimage_state->image0.committed,softimage_state->image0.active,softimage_state->image0.valid,
		softimage_state->image1.committed,softimage_state->image1.active,softimage_state->image1.valid);
	for (i = 0 ; i < sizeof(mode_table)/sizeof(struct  omciSoftwareImageState); i ++)
	{
		if (softimage_state->image0.committed == mode_table[i].img0.commit	&& 
			softimage_state->image0.active == mode_table[i].img0.active 	&& 
			softimage_state->image0.valid == mode_table[i].img0.valid		&&
			softimage_state->image1.committed == mode_table[i].img1.commit	&&
			softimage_state->image1.active == mode_table[i].img1.active 	&& 
			softimage_state->image1.valid == mode_table[i].img1.valid)
		{
			sprintf(cmd, "uci set gpon.common.OMCI_SoftWare_Image_State=%s", mode_table[i].value);
			system(cmd);
			omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"========== %d %s =========\r\n",__LINE__,mode_table[i].value);
			goto end;
		}
	}
	sprintf(cmd, "uci set gpon.common.OMCI_SoftWare_Image_State=%s", "SOFTWARE_IMAGE_STATE_S0");
	system(cmd);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"========== %d %s =========\r\n",__LINE__,"SOFTWARE_IMAGE_STATE_S0");
end:
	system("uci commit gpon");
	return 0;
#else
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
#endif
}
int omci_image_read_state(softimage_state_t *softimage_state)
{
#ifdef TCSUPPORT_OPENWRT
	char attr_val[4] = {0};
	char cmd[256] = {0};
	char buffer[64] = {0};
	uint8_t bootflag = 0;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] Enter .\n",__FUNCTION__,__LINE__);
	if(NULL == softimage_state){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]Parameter is Null.\n",__FUNCTION__,__LINE__);
		return -1;
	}
	omci_lib_uci_get("gpon.common.OMCI_SoftWare_Image_State", buffer, sizeof(buffer));
	if((0 == strncmp(buffer, "SOFTWARE_IMAGE_STATE_S4_0", strlen("SOFTWARE_IMAGE_STATE_S4_0")) ) ||
		(0 == strncmp(buffer, "SOFTWARE_IMAGE_STATE_S4_1", strlen("SOFTWARE_IMAGE_STATE_S4_1")) )){
		
		omci_lib_uci_get("gpon.SoftImage0.Committed", attr_val, sizeof(attr_val));
		softimage_state->image0.committed = (uint8_t)atoi(attr_val);
		omci_lib_uci_get("gpon.SoftImage0.Active", attr_val, sizeof(attr_val));
		softimage_state->image0.active = (uint8_t)atoi(attr_val);
		omci_lib_uci_get("gpon.SoftImage0.Valid", attr_val, sizeof(attr_val));
		softimage_state->image0.valid = (uint8_t)atoi(attr_val);
			
		omci_lib_uci_get("gpon.SoftImage1.Committed", attr_val, sizeof(attr_val));
		softimage_state->image1.committed = (uint8_t)atoi(attr_val);
		omci_lib_uci_get("gpon.SoftImage1.Active", attr_val, sizeof(attr_val));
		softimage_state->image1.active = (uint8_t)atoi(attr_val);
		omci_lib_uci_get("gpon.SoftImage1.Valid", attr_val, sizeof(attr_val));
		softimage_state->image1.valid = (uint8_t)atoi(attr_val);
			
	}else {
		omci_image_get_bootflag(&bootflag);
		if(bootflag == 0){
			softimage_state->image0.committed = 1;
			softimage_state->image0.active = 1;
			softimage_state->image0.valid = 1;
			softimage_state->image1.committed = 0;
			softimage_state->image1.active = 0;
			omci_lib_uci_get("gpon.SoftImage1.Valid", attr_val, sizeof(attr_val));
			softimage_state->image1.valid = (uint8_t)atoi(attr_val);
		}else{
			softimage_state->image0.committed = 0;
			softimage_state->image0.active = 0;
			omci_lib_uci_get("gpon.SoftImage0.Valid", attr_val, sizeof(attr_val));
			softimage_state->image0.valid = (uint8_t)atoi(attr_val);
			softimage_state->image1.committed = 1;
			softimage_state->image1.active = 1;
			softimage_state->image1.valid = 1;
		}
		sprintf(cmd, "uci set gpon.SoftImage0.Committed=%d", softimage_state->image0.committed);
		system(cmd);
		sprintf(cmd, "uci set gpon.SoftImage0.Active=%d", softimage_state->image0.active);
		system(cmd);
		sprintf(cmd, "uci set gpon.SoftImage0.Valid=%d", softimage_state->image0.valid);
		system(cmd);
		sprintf(cmd, "uci set gpon.SoftImage1.Committed=%d", softimage_state->image1.committed);
		system(cmd);
		sprintf(cmd, "uci set gpon.SoftImage1.Active=%d", softimage_state->image1.active);
		system(cmd);
		sprintf(cmd, "uci set gpon.SoftImage1.Valid=%d", softimage_state->image1.valid);
		system(cmd);
		system("uci commit gpon");
	}
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "----------------softImage0----------\n");
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "committed=%d,active=%d,valid=%d\n",softimage_state->image0.committed,softimage_state->image0.active,softimage_state->image0.valid);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "----------------softImage1----------\n");
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "committed=%d,active=%d,valid=%d\n",softimage_state->image1.committed,softimage_state->image1.active,softimage_state->image1.valid);
	return 0;
#else
	//ALU OLT IOT Issue
	if(NULL == softimage_state){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "softimage_state == NULL!!!\n",__FUNCTION__,__LINE__);
		return -1;
	}
	
	softimage_state->image0.committed = 1;
	softimage_state->image0.active = 1;
	softimage_state->image0.valid = 1;
	softimage_state->image1.committed = 0;
	softimage_state->image1.active = 0;
	softimage_state->image1.valid = 1;
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP. Set default softimage state for BSP\n",__FUNCTION__,__LINE__);
    return 0; 
#endif
}

/*WAN Interface*/
int omci_wan_create(uint16_t IPHostIstId)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_wan_delete(uint16_t IPHostIstId)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_wan_delete_by_type(uint32_t svc_type)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_wan_clear_all(void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
 int omci_wan_set_attr(uint16_t IPHostIstId, char* path)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_wan_get_attr(int type ,uint16_t IPHostIstId, char* buf,uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_wan_set_effect(uint16_t iphostId)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
void omci_wan_dump_web_rcd(void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return;
}

void omci_wan_dump_iphost_wan(void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return;
}

int omci_wan_init_web_rcd( void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}

void omci_update_wan_rcd_info(void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return;
}

int omci_wan_recovery_web(uint32_t svc_type)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
/********************************************************************************************************
9.9.1 pptp pots uni
*********************************************************************************************************/
int omci_voip_get_admin_state(char *buf, uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_rx_gain(char *buf, uint8_t buf_size, uint16_t instance_id)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_tx_gain(char *buf, uint8_t buf_size, uint16_t instance_id)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_hook_state(char *buf, uint8_t buf_size, uint16_t instance_id)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

int omci_voip_set_admin_state(char *buf, uint16_t portId)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_rx_gain(char *buf, uint16_t instance_id)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_tx_gain(char *buf, uint16_t instance_id)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

/********************************************************************************************************
9.9.2 sip user data
*********************************************************************************************************/
int omci_voip_get_sip_disp_name(char *buf, uint8_t buf_size, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_voice_exp_time(char *buf, uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

int omci_voip_set_user_part_aor(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: telephone number %s.\n",__FUNCTION__,__LINE__, buf);

	voip_set_telephone_number(buf);
    return 0;
}
int omci_voip_set_sip_disp_name(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_sip_user_name(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d] %d sip user name %s.\n",__FUNCTION__,__LINE__, index, buf);

	voip_set_user_name(buf);
    return 0;
}
int omci_voip_set_sip_password(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d] %d sip user password %s.\n",__FUNCTION__,__LINE__, index, buf);

	voip_set_user_password(buf);
    return 0;
}

int omci_voip_set_sip_port_id(uint16_t port_id, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d] %d port_id %d.\n",__FUNCTION__,__LINE__, index, port_id);

	voip_set_port_id(port_id);
    return 0;
}

int omci_voip_set_sip_enable(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_sip_uri(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_voice_exp_time(char *buf)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_reset_sip_user_entry(uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}

/********************************************************************************************************
9.9.3 sip agent config data
*********************************************************************************************************/
int omci_voip_get_reg_exp_time(char *buf, uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_re_reg_time(char *buf, uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_sip_status(char *buf, uint8_t buf_size, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

int omci_voip_set_proxy_enable(char *buf)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

// parse the URL string and get the addr and port
static int  omci_voip_parse_url(IN_OUT char * buff /*Careful! Crash if NULL*/,  OUT char **  addr, OUT char ** port)
{
	if(buff == NULL || addr == NULL || port == NULL){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: ERROR:parameter is NULL!\n",__FUNCTION__,__LINE__);
		return -1;
	}
    omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: String to Parse: %s\n", __FUNCTION__,__LINE__,buff);
    
    *addr = buff;
    *port = NULL;
    
    char * delimter_pos = strchr(buff, ':');

    if ( NULL != delimter_pos )
    {
        * delimter_pos = '\0';
        * port =  ++delimter_pos;
    }
	
	return 0;
}

int omci_voip_set_proxy_server_addr(char *buf)
{
	char *addr = NULL,  *port = NULL;

	if(buf == NULL){
		return -1;
	}
	if(omci_voip_parse_url(buf, &addr, &port) != 0)
    {
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_parse_url fail!\n",__FUNCTION__,__LINE__);
        return -1;
	}

	voip_set_proxy_server(addr);

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: addr %s, port %s \n",__FUNCTION__,__LINE__, addr, port);
    return 0;
}

int omci_voip_set_host_domain(char *buf)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "host domain %s \n",__FUNCTION__,__LINE__, buf);

	voip_set_register_server(buf);

	return 0;
}

int omci_voip_set_out_proxy_addr(char *buf)
{
	char *addr = NULL,  *port = NULL;

	if(buf == NULL){
		return -1;
	}
	if(omci_voip_parse_url(buf, &addr, &port) != 0)
    {
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]: omci_voip_parse_url fail!\n",__FUNCTION__,__LINE__);
        return -1;
	}

	voip_set_out_proxy_add(addr);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: addr %s, port %s \n",__FUNCTION__,__LINE__, addr, port);
    return 0;
}
int omci_voip_set_reg_exp_time(char *buf)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_re_reg_time(char *buf)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}
int omci_voip_set_sip_reg(char *buf)
{
	voip_set_register_server(buf);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]: register server %s \n",__FUNCTION__,__LINE__, buf);
    return 0;
}
int omci_voip_reset_sip_agent_cfg(void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
	return 0;
}

/********************************************************************************************************
9.9.5 voip media profile
*********************************************************************************************************/
int omci_voip_get_fax_mode(char *buf, uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_codec_select(char *buf, uint8_t buf_size, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_pack_period_select(char *buf, uint8_t buf_size, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_silence_suppress(uint8_t *silence_flag, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_oob_dtmf(char *buf, uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

int omci_voip_set_fax_mode(char *buf)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_codec_select(uint8_t codec_type, uint8_t index)
{
    return 0;
}
int omci_voip_set_pack_period_select(uint8_t codec_type,char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_silence_suppress(uint8_t silence_flag, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_oob_dtmf(char *buf)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

/*******************************************************************************************************************************
9.9.10 network dial plan table
********************************************************************************************************************************/
int omci_voip_set_digital_map(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

/********************************************************************************************************
9.9.11 voip line status
*********************************************************************************************************/
int omci_voip_get_codec_used(uint8_t *index_pri, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_voice_server_status(omci_voip_ser_status_t *ser_status, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_port_session_type(omci_voip_port_ses_type_t *port_sess_type, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_device_status(omci_voip_dev_status_t *dev_status, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_packet_period( uint16_t *pkt_period, omci_voip_pkt_period_t period_index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_line_state(omci_voip_line_state_t *line_state, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
/********************************************************************************************************
9.9.16 mgc config data
*********************************************************************************************************/
int omci_voip_get_term_id_base(char *buf, uint8_t buf_size)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

int omci_voip_set_mgc_info(char *buf, uint8_t index)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_term_id_base(char *term_id_base)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

/********************************************************************************************************
9.9.18 voip config data
*********************************************************************************************************/
int omci_voip_get_avail_signal_protoc(uint8_t *protocol)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_signal_protocol_used(uint8_t *protocol)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_get_profile_version(char *version, uint8_t version_len)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

int omci_voip_set_signal_protocol_used(uint8_t protocol)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}
int omci_voip_set_config_method_used(uint8_t cfg_method)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

uint8_t omci_voip_get_config_method_used(void)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

int omci_is_voip_related_me(uint16_t class_id)
{
	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "Enter [%s][%d]: BSP Do nothing.\n",__FUNCTION__,__LINE__);
    return 0;
}

